<?php
namespace Admin\Controller;
use Think\Controller;
header('content-type:text/html;charset=utf-8');
class PersonController extends AdminController{
	function __construct(){
		parent::__construct();
		
		/* if(!$_SESSION['home']['user']){
			echo "<script>alert('很抱歉，您尚未登录﻿ ');window.location.href='".__APP__."/Admin/Index/login'</script>";
		} */
		
	}
	
	//项目竞标列表
	public function project_list(){
		$cond=array();
		if($_POST['project_name']){
			$cond['project_name']=I("post.project_name");
			$this->assign("project_name",$cond['project_name']);
		}
		
		$info=getpage("project",10,$cond,"add_time desc");//信息
		$this->assign("info",$info);
		$this->display();
	}

	//添加修改项目竞标
	public function add_project(){
	$model=M("project");
		if($_POST){
		
			//表单提交
			$post=I("post.");
			
			if(!$_POST['type']){
				//添加
				$post['add_time']=date("Y-m-d H:i:s",time());
				//$post['add_person']=$_SESSION['admin']['id'];
				$post['add_person']=1;
				$model->create($post);
				$res=$model->add();
				if($res){
					echo "<script>alert('添加成功');window.location.href='project_list'</script>";
					//$this->redirect("Course/public_list");
				}else{
					$url=$_SERVER['HTTP_REFERER'];
					echo "<script>alert('添加失败');window.location.href='".$url."'</script>";
				}
			}else{
				//修改
				$model->create($post);
				$res=$model->save();
				if($res){
					echo "<script>alert('修改成功');window.location.href='project_list'</script>";
					
				}else{
					$url=$_SERVER['HTTP_REFERER'];
					echo "<script>alert('修改失败');window.location.href='".$url."'</script>";
				}
			}
		}else{
			//进入页面
			if(!$_GET['type']){
				//进入添加页面
				$action="项目竞标添加";
					
			}else{
				//进入修改页面
				$id=I("get.id");
				$action="项目竞标修改";
				$info=$model->where("id=$id")->find();
				$this->assign("info",$info);
				
			}
			$this->assign("action",$action);
			$this->display();
		}
	}
	//课程留言
	public function comment(){
		$cond=array();
		if($_POST['course_name']){
			$cond['course_name']=I("post.course_name");
			$this->assign("course_name",$cond['course_name']);
		}
		
		$info=getpage("comment",10,$cond,"add_time desc");//收藏信息
		$this->assign("info",$info);
		$this->display();
		
	}
	//课程收藏
	public function collect(){
		//$model=M("collect");
		$cond=array();
		if($_POST['course_name']){
			$cond['course_name']=I("post.course_name");
			$this->assign("course_name",$cond['course_name']);
		}
		
		$info=getpage("collect",10,$cond,"add_time desc");//收藏信息
		$this->assign("info",$info);
		$this->display();
	}
	//删除
	public function del(){
		$table=I("post.table");
		$id=I("post.id");
		$model=M($table);
		$res=$model->where("id=$id")->delete();
		if($res){
			echo $_SERVER['HTTP_REFERER'];
		}
 		/* echo $_SERVER['HTTP_REFERER'];
 		die(); */
	}
	
	
}